﻿using AutoMapper;
using MediatR;
using SmartCity.ProcessEngine.API.Write.Application.Commands.Forms;
using SmartCity.ProcessEngine.Domain;
using SmartCity.ProcessEngine.Errorcode;
using SmartCity.ProcessEngine.Infrastructure.Interfaces;

namespace SmartCity.ProcessEngine.API.Write.Application.CommandHandlers.Forms
{
    /// <summary>
    /// 处理
    /// </summary>
    public class FormUpdateCommandHandler:IRequestHandler<FormUpdateCommand,ApiResult<int>>
    {
        private readonly IBaseRepository<WF_Form> formRep;
        private readonly IMapper mapper;

        public FormUpdateCommandHandler(IBaseRepository<WF_Form> formRep,IMapper mapper)
        {
            this.formRep = formRep;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(FormUpdateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.code = ApiEnum.UpdateSuccess;
            result.message = "修改成功";

            WF_Form entity = mapper.Map<WF_Form>(request);
            await formRep.UpdateAsync(entity);

            return await Task.FromResult(result);
        }
    }
}
